package com.example.su_shi_tan_bas_lib.view

import android.content.Context
import android.util.AttributeSet
import android.view.MotionEvent
import android.widget.ListView

class LabelListView
@JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0)
    :ListView(context, attrs, defStyleAttr){

    override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
        val heightSpec = if (layoutParams.height == LayoutParams.WRAP_CONTENT) {
            //让GridView的高度为Wrap_content根据内容自适应高度
            MeasureSpec.makeMeasureSpec(
                Int.MAX_VALUE shr 2, MeasureSpec.AT_MOST
            )
        } else {
            heightMeasureSpec
        }
        super.onMeasure(widthMeasureSpec, heightSpec)
    }

    override fun dispatchTouchEvent(ev: MotionEvent): Boolean {

        //禁止滑动
        return if (ev.action == MotionEvent.ACTION_MOVE) true else super.dispatchTouchEvent(ev)
    }
}